/**
 *
 * @description: set-map数据结构
 * @author: junyong.hong
 * @createTime: 2018/3/28
 * @version: 1.0.0.0
 * @history:
 *    1、
 *    2、
 *
 */
{
    let list = new Set();
    list.add(5);
    list.add(7);
    // 判断长度 输出：2
    console.log('size',list.size);
}

{
    let arr = [1,2,3,4,5];
    let list = new Set(arr);
    // 5
    console.log('size', list.size);
}

{
    // 运用场景：去重
    let list = new Set();
    list.add(1);
    list.add(2);
    // 重复元素，没有添加成功
    list.add(1);
    // {1, 2}
    console.log('list',list);


    let arr = [1,2,3,1,2];
    let list2 = new Set(arr);
    // 输出{1,2,3}
    console.log('unique',list2);
}

{
    let arr = ['add','delete','clear','has'];
    let list = new Set(arr);

    // 判断list里面有没有add这个值 输出：true
    console.log('has', list.has('add'));
    // 删除list
    console.log('delete', list.delete('add'), list);
    // 清空list
    list.clear();
    console.log('list',list);
}

{
    let arr = ['add','delete','clear','has'];
    let list = new Set(arr);


    for(let key of list.keys()){
        // keys add
        // keys delete
        // keys clear
        // keys has
        console.log('keys',key);
    }
    for(let value of list.values()){
        // values add
        // values delete
        // values clear
        // values has
        console.log('values',value);
    }
    for(let value of list){
        // values add
        // values delete
        // values clear
        // values has
        console.log('values',value);
    }
    for(let [key,value] of list.entries()){
        // entries add add
        // entries delete delete
        // entries clear clear
        // entries has has
        console.log('entries',key,value)
    }

    list.forEach(function (item) {
        // add
        // delete
        // clear
        // has
        console.log(item);
    })
}


{
    // 和set的数据类型不一样，WeakSet只是能对象，不能是数值，例如boolean
    // WeakSet对象这块，弱引用（不会检测对象在其他地方引用到，意味着不会跟垃圾回收机制挂钩到，简单说：WeakSet是一个地址的引用）
    // WeakSet没有clean、没有set、不能遍历
    let weakList = new WeakSet();

    let arg = {};
    weakList.add(arg);
    // 报错
    // weakList.add(2);
    console.log('weakList',weakList);
}


{
    let map = new Map();
    let arr = ['123'];

    map.set(arr,456);
    console.log('map', map, map.get(arr));      // key是123 value是456
}

{
    let map = new Map([['a',123],['b',456]]);
    console.log('map args', map);                   // {"a" => 123, "b" => 456}
    console.log('size', map.size);                  // 2
    console.log('delete', map.delete('a'), map);    // {"b" => 456}
    console.log('clear', map.clear(), map);         // {}
}

{
    // 与set和weakSet是一样的
    let weakmap = new WeakMap();
}

